package com.meevle.vo;

import java.io.Serializable;
import java.util.Date;

import org.red5.core.ApplicationSettings;


public class SlotVO implements Serializable{

	private static final long serialVersionUID = 1L;
	
	//TODO: owner weg
	private UserVO owner;
	private String name;
	private Date timeCreated;
	private String filename;
	private String directory;
	private int index;
	
	public SlotVO()
	{}
	
	/**
	 * Creates a new TrackObject that instatiates tha owner, the filename and the directory
	 * @param user the user which would be owner of the track
	 */
	public SlotVO(UserVO owner)
	{
		this(owner, null, null, -1);
	}
	
	public SlotVO(UserVO owner, Date timeCreated, String name, int index)
	{
		setOwner(owner);
		setTimeCreated(timeCreated);
		setName(name);
		setIndex(index);
		
		//sets the filename and the directory of the recorded and saved track
		setFilename( String.valueOf( System.currentTimeMillis() )+".mp3" );
		setDirectory(ApplicationSettings.getInstance().getUserTracksPath(owner.getUsername()));
	}

	public UserVO getOwner() {
		return owner;
	}

	public void setOwner(UserVO owner) {
		this.owner = owner;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public Date getTimeCreated() {
		return timeCreated;
	}

	public void setTimeCreated(Date timeCreated) {
		this.timeCreated = timeCreated;
	}
	public int getIndex() {
		return index;
	}
	
	public void setIndex(int index) {
		this.index = index;
	}

	public String getFilename() {
		return filename;
	}

	public void setFilename(String filename) {
		this.filename = filename;
	}

	public String getDirectory() {
		return directory;
	}

	public void setDirectory(String directory) {
		this.directory = directory;
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((name == null) ? 0 : name.hashCode());
		result = prime * result + ((owner == null) ? 0 : owner.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		SlotVO other = (SlotVO) obj;
		if (name == null) {
			if (other.name != null)
				return false;
		} else if (!name.equals(other.name))
			return false;
		if (owner == null) {
			if (other.owner != null)
				return false;
		} else if (!owner.equals(other.owner))
			return false;
		return true;
	}

	@Override
	public String toString()
	{
		return "\nOwner: " + owner.getUsername() + "\nTrackname: " + name;
	}
	
	
}
